package com.bort.system.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bort.system.info.DeskInfo;
import com.bort.system.service.TDeskService;
import com.bort.system.service.TOrderService;
import com.bort.system.utils.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/mobile")
public class MobileApiController {

    @Resource
    TOrderService orderService;

    @Resource
    TDeskService deskService;

    @RequestMapping(value = "/data",method = RequestMethod.GET)
    public Result<Map<String,Object>> getData(){
        Result<Map<String, BigDecimal>> statistic = orderService.dataStatistic(new HashMap<>());
        Page<DeskInfo> pager = new Page<>();
        pager.setCurrent(1);
        pager.setSize(6);
        Map<String,Object> map = new HashMap<>();
        List<DeskInfo> deskInfos = deskService.getDeskList(pager,map);
        List<DeskInfo> deskInfoList = deskInfos.stream().filter(desk -> "1".equals(desk.getStatus()) || "2".equals(desk.getStatus())).collect(Collectors.toList());
        Map<String,Object> data = new HashMap<>();
        data.put("deskList",deskInfoList);
        data.put("statistic",statistic);
        return Result.success(data);
    }

}
